package com.javalaoniu.tool.utils;

import java.security.SecureRandom;
import java.util.Random;

/**
 * 随机工具类
 *
 * @author: xianninig
 * @date: 2018/8/30 10:38
 */
public class RandomUtil {

    private static final Random RANDOM = new SecureRandom();

    private RandomUtil() {
    }

    /**
     * 生成0-n之间的数
     *
     * @param n n>1
     * @return [0, n)
     */
    public static int randomInt(int n) {
        return RANDOM.nextInt(n);
    }

    /**
     * 返回指定范围内的随机数
     *
     * @param from > 1
     * @param to   > from
     * @return [to - from, to)
     */
    public static int randomInt(int from, int to) {
        return RANDOM.nextInt(to - from) + from;
    }

}
